package com.example.anliku.controller;

import com.alibaba.fastjson.JSON;
import com.example.anliku.entity.Clazz;
import com.example.anliku.entity.ExampleClazz;
import com.example.anliku.entity.ExampleKnowledge;
import com.example.anliku.entity.Message;
import com.example.anliku.entity.clazzBody.clazzRetBody;
import com.example.anliku.entity.clazzBody.clazzRetGxBody;
import com.example.anliku.service.ClazzService;
import com.example.anliku.service.ExampleClazzService;
import com.example.anliku.service.ExampleKnowledgeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "课程模块")
@RestController
@RequestMapping("/api/clazz")
public class ClazzController {
    @Resource
    private ClazzService clazzService;

    @Resource
    private ExampleClazzService exampleClazzService;

    @ApiOperation(value = "添加课程")
    @PostMapping("/one")
    public Message insert(Clazz clazz) {
        return clazzService.insertSelective(clazz);
    }

    @ApiOperation(value = "删除课程")
    @DeleteMapping("/delete")
    public Message delete(Integer clazzId) {
        return clazzService.deleteByPrimaryKey(clazzId);
    }

    @ApiOperation(value = "删除案例与课程对应关系")
    @DeleteMapping("/deleteClazz")
    public Message deleteexampleClazz(Integer exampleClazzId) {
        return exampleClazzService.deleteByPrimaryKey(exampleClazzId);
    }

    @ApiOperation(value = "修改课程")
    @PostMapping("/put")
    public Message update(Clazz clazz) {
        return clazzService.updateByPrimaryKeySelective(clazz);
    }

    @ApiOperation(value = "获取所有课程")
    @GetMapping("/all")
    public Message selectAll(){
        return clazzService.selectAll();
    }

    @ApiOperation(value = "根据课程id获取课程")
    @GetMapping("/one")
    public Message selectByPrimaryKey(Integer clazzId){
        return clazzService.selectByPrimaryKey(clazzId);
    }

    @ApiOperation(value = "批量添加课程与案例对应关系")
    @PostMapping("/list")
    public Message batchInsert(String list) {
        List<ExampleClazz> exampleClazzList = JSON.parseArray(list,ExampleClazz.class);
        return exampleClazzService.insertList(exampleClazzList);
    }

    @ApiOperation(value = "批量添加课程与案例对应关系(Body)")
    @PostMapping("/listGx")
    public Message batchInsertGx(@RequestBody  List<clazzRetGxBody> list) {
        return exampleClazzService.insertListGx(list);
    }
    @ApiOperation(value = "批量添加课程标签")
    @PostMapping("/listtab")
    public Message bInsert(String list) {
        List<Clazz> ClazzList = JSON.parseArray(list,Clazz.class);
        return clazzService.insertList(ClazzList);
    }

    @ApiOperation(value = "批量添加课程标签(Body)")
    @PostMapping("/listtabBody")
    public Message listtabBody(@RequestBody  List<clazzRetBody> list) {
        return clazzService.listtabBody(list);
    }
}
